package com.pms.init;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.manager.RelatedModel;
import com.espirit.eap.manager.TabbedModel;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.googlecode.cswish.annotation.Dependence;
import com.pms.house.House;
import com.pms.manager.HouseDebitChargeItemStandard;
@Dependence(value={
		"com.pms.init.HouseDebitChargeItemStandardBuilder",
})
@Component
public class HouseBuilder extends ModelBuilderSupport {

	static final String BUILDING = "building";
	static final String CODE = "code";
	static final String BUILDAREA = "buildArea";
	static final String INNERAREA = "innerArea";
	static final String PUBLICAREA = "publicArea";
	static final String REMARK = "remark";
	static final String HOUSETYPE = "houseType";
	static final String HOUSESTATUS = "houseStatus";
	
	@Override
	public boolean init() {
		return super.setClass(House.class, "House", "房屋信息");
	}

	@Override
	public void buildFields() {
		addModelField(BUILDING, "Building", "楼宇");
		addModelField(CODE, "Code", "编码");
		addModelField(BUILDAREA, "Build Area)", "建筑面积");
		addModelField(INNERAREA, "Inner Area", "套内面积");
		addModelField(PUBLICAREA, "Public Area", "公摊面积");
		addModelField(REMARK, "Remark", "说明");
		addModelField(HOUSETYPE, "House Type", "房屋类型");
		addModelField(HOUSESTATUS, "Status", "房屋状态");
	}
	
	@Override
	public void prepareLayoutElements() {
		super.prepareLayoutElements();
	}
	
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(BUILDING, CODE, HOUSETYPE, HOUSESTATUS));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(CODE, BUILDING, HOUSETYPE, BUILDAREA, INNERAREA, PUBLICAREA, HOUSESTATUS, REMARK));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(BUILDING, CODE, HOUSETYPE, BUILDAREA, INNERAREA, PUBLICAREA, HOUSESTATUS, REMARK));
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
		if (name.equals(HOUSETYPE)){
			element.setTagName("dictselect");
			element.addExProperty("name", HOUSETYPE);
			element.addExProperty("type", HOUSETYPE);
		} else if (HOUSESTATUS.equals(name)){
			element.setTagName("dictselect");
			element.addExProperty("name", HOUSESTATUS);
			element.addExProperty("type", HOUSESTATUS);
		} 
		return element;
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{CODE, BUILDING});
	}
	
	protected RelatedModel[] getRelatedModels(){
		RelatedModel getLayout = new RelatedModel(this.clazz, "getLayout");
		return new RelatedModel[]{getLayout};
	}
	
	protected TabbedModel[] getTabbedModels(){
		TabbedModel houseDebitChargeItemStandard = new TabbedModel(HouseDebitChargeItemStandard.class, SEARCHRELATEDRESULT, "house");
		return new TabbedModel[]{houseDebitChargeItemStandard};
	}
}
